/**
 * 
 */
package net.oauth.transport.http;

import java.util.Map;
import java.util.Map.Entry;

import net.oauth.util.ParameterPairer;

/**
 * @author Buhake Sindi
 * @since 08 Febuary 2012
 *
 */
public abstract class HttpParameterPairer extends ParameterPairer<String[]> {

	/**
	 * @param startDelimiter
	 * @param endDelimiter
	 * @param pairDelimiter
	 */
	protected HttpParameterPairer(String startDelimiter, String endDelimiter, String pairDelimiter) {
		super(startDelimiter, endDelimiter, pairDelimiter);
	}

	/* (non-Javadoc)
	 * @see net.oauth.util.QueryStringBuilder#toString(java.util.Map)
	 */
	@Override
	public String toString(Map<String, String[]> attributeMap) {
		// TODO Auto-generated method stub
		if (attributeMap == null) {
			return null;
		}
		
		StringBuilder sb = new StringBuilder();
		for (Entry<String, String[]> entry : attributeMap.entrySet()) {
			for (String value : entry.getValue()) {
				if (sb.length() > 0) {
					sb.append(pairDelimiter);
				}
				
				sb.append(entry.getKey()).append(startDelimiter).append(value).append(endDelimiter);
			}
		}
		
		return sb.toString();
	}
}
